<?php
    //判断字符串长度
    function strLenMin($str){
        return strlen($str)<6;
    }
    //判断字符串是否为空
    function isEmpty($str){
        return $str == null || $str == empty($str);
    }
    $message = "";
    foreach(['username','password'] as $key =>$value){
        if(!isset($_POST[$value])){
            $message = $value."为必填值";
            break;
        }
        if($value === "password" && strLenMin($_POST[$value])){
            $message = $value."不能小于6";
            break;   
        }
        if(isEmpty($_POST[$value])){
            $message = $value."不能为空";
            break;
        }
    }
 $responseData = [
    'code'=>0,
    'msg'=>$message,
    'data'=>[]
 ];
 if($message != ""){
    $responseData['code'] = 1;
 }
 print_r(json_encode($responseData,JSON_UNESCAPED_UNICODE));
